#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D long double
#define N 3003
int a[N][N],can[N];
signed main(){
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c;cin>>c;a[i][j]=c-'a'+1;
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		int sum;vector<int> va,vb;
		for(int j=1;j<=m;j++)	can[j]=a[i][j];
		for(int j=i+1;j<=n;j++){
			sum=0;
			for(int k=1;k<=m;k++){
				can[k]=((can[k]!=a[j][k])?-1:can[k]);sum+=(can[k]>0);
			}
			if(sum<=1)	break;
			int zt=-1,cnt=0;
			for(int k=1;k<=m;k++){
				if(zt==a[j][k]&&zt==a[i][k]){
					if(can[k]==zt){
						ans+=cnt;cnt++;
					}
				}else{
					zt=(a[j][k]==a[i][k])?a[j][k]:-1;cnt=(can[k]==zt);
				}
			}
		}
	}
	cout<<ans;
	return 0;
}
/*
3 4
aaaa
aaba
aaaa
*/
